#!/usr/bin/env python3
"""
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)
"""
import sys
import math


def main():
    data = sys.stdin.read().split('\n')
    idx = 0

    num_rows = int(data[idx])
    idx += 1

    # 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

    total_pnl = 0.0
    num_trades = 0
    win_rate = 0.0
    max_drawdown = 0.0
    sharpe = 0.0
    sortino = 0.0
    max_consecutive_wins = 0

    # TODO: Your implementation here

    print(f"{total_pnl:.6f}")
    print(num_trades)
    print(f"{win_rate:.6f}")
    print(f"{max_drawdown:.6f}")
    print(f"{sharpe:.6f}")
    print(f"{sortino:.6f}")
    print(max_consecutive_wins)


if __name__ == '__main__':
    main()
