You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please provide any additional information below:
here is modified estimate_intraday
defestimate_intraday(returns, positions, transactions, EOD_hour=23):
""" Intraday strategies will often not hold positions at the day end. This attempts to find the point in the day that best represents the activity of the strategy on that day, and effectively resamples the end-of-day positions with the positions at this point of day. The point of day is found by detecting when our exposure in the market is at its maximum point. Note that this is an estimate. Parameters ---------- returns : pd.Series Daily returns of the strategy, noncumulative. - See full explanation in create_full_tear_sheet. positions : pd.DataFrame Daily net position values. - See full explanation in create_full_tear_sheet. transactions : pd.DataFrame Prices and amounts of executed trades. One row per trade. - See full explanation in create_full_tear_sheet. Returns ------- pd.DataFrame Daily net position values, resampled for intraday behavior. """# Construct DataFrame of transaction amountstxn_val=transactions.copy()
txn_val.index.names= ['date']
txn_val['value'] =txn_val.amount*txn_val.pricetxn_val=txn_val.reset_index().pivot_table(
index='date', values='value',
columns='symbol').replace(np.nan, 0)
# index convert to datetime indextxn_val=txn_val.reset_index()
txn_val['date'] =pd.to_datetime(txn_val['date'])
txn_val.set_index('date', inplace=True)
# Cumulate transaction amounts each daytxn_val=txn_val.groupby(pd.Grouper(freq='24H')).cumsum()
print(txn_val)
# Calculate exposure, then take peak of exposure every daytxn_val['exposure'] =txn_val.abs().sum(axis=1)
condition= (txn_val['exposure'] ==txn_val.groupby(
pd.Grouper(freq='24H'))['exposure'].transform(max))
txn_val=txn_val[condition].drop('exposure', axis=1)
# Compute cash deltatxn_val['cash'] =-txn_val.sum(axis=1)
# Shift EOD positions to positions at start of next trading daypositions_shifted=positions.copy().shift(1).fillna(0)
starting_capital=positions.iloc[0].sum() / (1+returns[0])
positions_shifted.cash[0] =starting_capital# Format and add start positions to intraday position changestxn_val.index=txn_val.index.normalize()
corrected_positions=positions_shifted.add(txn_val, fill_value=0)
corrected_positions.index.name='period_close'corrected_positions.columns.name='sid'returncorrected_positions
Versions
Pyfolio version:
Python version:
Pandas version:
Matplotlib version:
The text was updated successfully, but these errors were encountered:
Problem Description
pyfoliozer = firstStrat.analyzers.getbyname('pyfolio')
returns, positions, transactions, gross_lev = pyfoliozer.get_pf_items()
Please provide the full traceback:
Please provide any additional information below:
here is modified estimate_intraday
Versions
The text was updated successfully, but these errors were encountered: