Hi,
At the beginning of each new year, I would like the algo to tell me what were the best X months of last year.
It is easy with python in Jupyter notebook as I can use monthly frequency when I download Yahoo quote but I am struggling when I try to implement the same thing in an algo.
Any idea ?
Below is an example of what I would like to do in my algo:
(This will print the best five month of year 2013)
import pandas as pd
import numpy as np
df = pd.read_csv('SPY_2013_monthly.csv')
df['Return'] = (df['Close'] / df['Open']) - 1
df['month'] = df['Date'].map(lambda x: str(x)[5:-3])
col_useful = ['month', 'Return']
df = df[col_useful]
df = df.groupby('month').sum()
df = df.sort_values(by='Return', ascending=0)
df[0:5]
output:
month Return
10 --> 0.139218
01 --> 0.075043
02 --> 0.070630
11 --> 0.056078
03 --> 0.055084
Thank you in advance.
Chris