/**
 * GetSharpe.io — Signal Backtester
 *
 * Simulate a trading signal backtest and compute performance metrics.
 *
 * Input format (stdin):
 *   Line 1: NUM_ROWS
 *   Lines 2..N+1: TIMESTAMP,PRICE,SIGNAL
 *     - SIGNAL is 1 (long), -1 (short), or 0 (flat)
 *
 * Output format (stdout): 7 lines:
 *   TOTAL_PNL        (6 decimal places)
 *   NUM_TRADES        (integer — count of signal changes)
 *   WIN_RATE          (6 decimal places — fraction of profitable trades)
 *   MAX_DRAWDOWN      (6 decimal places — peak-to-trough in cumulative PnL)
 *   SHARPE_RATIO      (6 decimal places)
 *   SORTINO_RATIO     (6 decimal places)
 *   MAX_CONSECUTIVE_WINS (integer — longest streak of positive PnL rows)
 *
 * Compile: g++ -O2 -std=c++20 -o solution solution.cpp
 */

#include <cstdio>
#include <cstdlib>
#include <cmath>

int main() {
    int num_rows;
    scanf("%d", &num_rows);

    // TODO: Implement the backtester
    //
    // For each row:
    //   1. Parse timestamp, price, signal
    //   2. Compute PnL: prev_signal * (price - prev_price)
    //   3. Update cumulative PnL, track peak and drawdown
    //   4. Track trade boundaries (signal changes) and per-trade PnL
    //   5. Accumulate running sums for Sharpe/Sortino calculation
    //
    // Key formulas:
    //   Sharpe = (mean(pnl) / std(pnl)) * sqrt(NUM_ROWS)
    //   Sortino = (mean(pnl) / downside_dev) * sqrt(NUM_ROWS)
    //   downside_dev = sqrt(sum(negative_pnl^2) / total_pnl_count)  -- divide by TOTAL count, not just negatives
    //
    // All metrics can be computed in a single pass using running sums.

    double total_pnl = 0.0;
    int num_trades = 0;
    double win_rate = 0.0;
    double max_drawdown = 0.0;
    double sharpe = 0.0;
    double sortino = 0.0;
    int max_consecutive_wins = 0;

    // TODO: Your implementation here

    printf("%.6f\n", total_pnl);
    printf("%d\n", num_trades);
    printf("%.6f\n", win_rate);
    printf("%.6f\n", max_drawdown);
    printf("%.6f\n", sharpe);
    printf("%.6f\n", sortino);
    printf("%d\n", max_consecutive_wins);

    return 0;
}
