-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathComputing_Single_Strategy.py
641 lines (513 loc) · 23.7 KB
/
Computing_Single_Strategy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
import pandas as pd
import numpy as np
import scipy.stats as st
def calculate_portfolio_return(weights,returns,name):
'''
Calculate portfolio return over its history based on weights and returns of assets
portfolio_return(t) = weights(t-1) @ returns(t)
Parameters
-----------------
weights: dataframe, time-series weights of a few assets
returns: dataframe, time-series returns of a few assets
name: str, name of the strategy(return)
Return
-----------------
Series: time-series returns with name
'''
uniqueness = weights.columns.is_unique
matching = set(weights.columns).issubset(set(returns.columns))
if uniqueness and matching:
returns = returns[weights.columns]
output = pd.Series(index=weights.index.copy(),name=name)
for t in output.index:
#print(t)
if t == output.index[0]: # first date of the portfolio has no return
output[t] = 0
pre_t = t
else: # weights(t-1) @ returns(t) = portfolio_return(t)
realized_ret = returns.loc[(returns.index > pre_t)&(returns.index<=t)].add(1).prod(min_count=1)-1
output[t] = weights.loc[pre_t,:].dot(realized_ret)
pre_t = t
return output
else:
raise AttributeError('assets under weights are {} unique'.format('' if uniqueness else 'not')+'\n'+\
' assets under weights can {} be found under returns'.format('' if matching else 'not'))
def calculate_annualized_return(portfolio_return,freq,method='direct'):
'''
Calculate annualized return of a given portfolio return
Parameters
-----------------
portfolio_return: series, portfolio return of a strategy
freq: int,frequency of the portfolio return(number of periods within a year)
method: str, 'direct', total return --> annualized return
∏(1+portfolio_return(t))^(freq/N) - 1, for all t
'estimate', average return --> annualized return
(1 + mean(portfolio_return(t)))^freq - 1, for all t
Return
-----------------
result, float
'''
if method in ('direct','d'):
N = len(portfolio_return)
result = np.prod(portfolio_return+1)**(freq/N) - 1
elif method in ('estimate','e'):
result = (1+np.mean(portfolio_return))**freq - 1
else:
raise NameError('Only accept method direct/d or estimate/e ')
return result
def calculate_latest_annualized_returns(portfolio_return,freq):
'''
Calculate the latest 1/2/3/5/7/10 years annualized return.
∏(1+portfolio_return(t))^(freq/N) - 1, for all t starting from 1/2/3/5/7/10 years ago.
Parameters
-----------------
portfolio_return: series, portfolio return
name: str, name of the corresponding strategy/portfolio return
freq: int, frequency of portfolio(number of periods within a year)
Returns
-----------------
series, annualized returns with index of name of length of history
'''
lengths = [freq*i for i in [1,2,3,5,7,10] if freq*i <= len(portfolio_return)] #the maximum years allowed go back given portfolio history
ann_rets = [calculate_annualized_return(portfolio_return.tail(l),freq=freq) for l in lengths]
index = ["Latest Annualized Return {} Month".format(int(l/freq)*12) for l in lengths] # in terms of month
return pd.Series(ann_rets,index=index,name=portfolio_return.name)
def calculate_annualized_stdev(portfolio_return,freq,ddof=1):
'''
Calculate annualized standard deviation of a given portfolio return
Parameters
-----------------
portfolio_return: series, portfolio return of a strategy
freq: int,frequency of the portfolio return(number of periods within a year)
Return
-----------------
result, float
'''
return np.std(portfolio_return,ddof=ddof)*np.sqrt(freq)
def calculate_latest_annualized_stdev(portfolio_return,freq):
'''
Calculate the latest 1/2/3/5/7/10 years annualized standard deviation.
std(any_portfolio(t))*freq^0.5, for all t starting from 1/2/3/5/7/10 years ago.
Parameters
-----------------
portfolio_return: series, portfolio return
name: str, name of the corresponding strategy
freq: int, frequency of portfolio
Returns
-----------------
series, annualized standard deviations with index of name of length of history
'''
lengths = [freq*i for i in [1,2,3,5,7,10] if freq*i <= len(portfolio_return)] # the maximum years allowed go back given portfolio history
ann_stds = [calculate_annualized_stdev(portfolio_return.tail(l),freq=freq) for l in lengths]
index = ["Latest Standard Deviation {} Month".format(int(l/freq)*12) for l in lengths] # in terms of month
return pd.Series(ann_stds,index=index,name=portfolio_return.name)
def calculate_rolling_returns(portfolio_return,month_size,freq):
'''
Calculate rolling returns over the given window size for the portfolio
Parameters
-----------------
portfolio_return: series, portfolio return
month_size: int, window length in terms of month
freq: int, frequency of portfolio
Returns
-----------------
output: series, rolling returns start from the earliest possible date
'''
name = '{} {}-Month Rolling Return'.format(portfolio_return.name,month_size)
window = int(month_size/12*freq)
rolling_ret = portfolio_return.rolling(window).apply(lambda x: np.prod(x+1)-1,raw=True)
rolling_ret.name = name
return rolling_ret
def calculate_calendar_year_returns(portfolio_return,freq):
'''
Calculate calendar-year return.
Calendar year time index is defined as the following:
{t(y), all t in year y; y: all calendar years}
Given y, {t(y)} is the portfolio return for the year y
only length({t(y)}) >= freq, annualized return for year y would be computed
Parameters
-----------------
portfolio_return: series, portfolio return
freq: int, frequency of portfolio
Returns
-----------------
output: series, calendar year returns
'''
cal_ret = portfolio_return.groupby([lambda idx: idx.year]).apply(lambda x: np.prod(x+1)-1 if len(x)>=freq else np.nan)
return cal_ret
def calculate_percentile(portfolio_return,pos):
'''
Calculate percentiles of portfolio return
Parameters:
-----------
portfolio_return: pandas series, portfolio return
pos: float or list of float
Returns:
--------
float/numpy array
'''
return np.percentile(portfolio_return,pos)
def calculate_momentum(portfolio_return, N):
'''
Calculate momentum for portfolio return from N-1 periods till current time
Parameters
-----------------
portfolio_return: series, portfolio return
N: int, number of periods
Returns
-----------------
float, momentum based on N
'''
return np.prod(portfolio_return.tail(N)+1)-1
def calculate_return_risk_ratio(portfolio_return,freq):
'''
Calculate return risk ratio, annualized return of portfolio return and its annualized portfolio standard deviation
Parameters:
-----------
portfolio_return: pandas series, portfolio return
freq: freq: int, frequency of portfolio
Return:
-------
float,return risk ratio
'''
return calculate_annualized_return(portfolio_return,freq)/calculate_annualized_stdev(portfolio_return,freq)
def calculate_skewness(portfolio_return):
'''
Calculate skewness of portfolio return
Parameters:
-----------
portfolio_return: pandas series, portfolio return
Returns:
--------
float, skewness of portfolio return
'''
return st.skew(portfolio_return,nan_policy='omit') # skewness
def calculate_kurtosis(portfolio_return):
'''
Calculate skewness of portfolio return
Parameters:
-----------
portfolio_return: pandas series, portfolio return
Returns:
--------
float, skewness of portfolio return
'''
return st.kurtosis(portfolio_return,nan_policy='omit') # kurtosis
def calculate_VaR_CVaR(portfolio_return,method='norm_CVaR',alpha=0.05):
'''
Calculate VaR and CVaR based on approximation with normal distribution and t distribution
Parameters
-----------------
portfolio_return: series, portfolio return
alpha: float, 1-alpha means the VaR/CVaR level, by default 0.05
Returns
-----------------
series, 4 values for t_VaR,norm_VaR,t_CVaR,norm_CVaR
'''
mu_n, sig_n = st.norm.fit(portfolio_return)
nu, mu_t, sig_t = st.t.fit(portfolio_return)
t_VaR = abs(st.t.ppf(alpha,df=nu,loc=mu_t,scale=sig_t))
norm_VaR = abs(st.norm.ppf(alpha,loc=mu_n,scale=sig_n))
t_CVaR = (-1/alpha)*st.t.expect(args=(nu,),loc=mu_t,scale=sig_t,lb=-np.inf,ub=-t_VaR)
norm_CVaR =(-1/alpha)*st.norm.expect(loc=mu_n,scale=sig_n,lb=-np.inf,ub=-norm_VaR)
result = dict(zip(['t_VaR','norm_VaR','t_CVaR','norm_CVaR'],[t_VaR, norm_VaR, t_CVaR, norm_CVaR]))
if method is None:
return result
else:
return result[method]
def calculate_drawdown(portfolio_return):
'''
Calculate drawdown over the entire history of portfolio return
drawdown(t) = max(observed drawdown, change from peak(0,t) to time t)
Parameters
-----------------
portfolio_return: series, portfolio return
Returns
-----------------
output: series, drawdown over the entire portfolio history
'''
cum_ret = np.cumprod(1+portfolio_return) # total return over the history
drawdown_hist = pd.Series(index=portfolio_return.index.copy(),name=portfolio_return.name)
drawdown = 0
max_seen = 1
for t in drawdown_hist.index:
max_seen = max(max_seen,cum_ret[t]) # value of peak
drawdown = max(drawdown,1-cum_ret[t]/max_seen) # compare the current observed drawdown with change from peak till time t
drawdown_hist[t] = drawdown # update drawdown
return drawdown_hist
def calculate_max_drawdown(portfolio_return):
'''
Calculate max drawdown over the entire history of portfolio return
drawdown(t) = max(observed drawdown, change from peak(0,t) to time t)
max_drawdown = max({drawdown(t): all t})
Parameters
-----------------
portfolio_return: pandas series, portfolio return
Returns
-----------------
float
'''
return np.max(calculate_drawdown(portfolio_return))
def calculate_batting_avg(target,benchmark):
'''
Calculate batting average value for target portfolio against benchmark portfolio
M = # of time points when target return > benchmark return
N = # of all time points
batting average = M/N
Parameters
-----------------
target: series, portfolio return
benchmark: series, portfolio return
Return
-----------------
float: batting average belonging to interval (0,1)
'''
excess_ret = np.subtract(target,benchmark)
return np.sum(excess_ret>0)/np.sum(excess_ret.notna())
def calculate_beta(target,benchmark,rf):
'''
Calculate beta of excess returns, using OLS method, between target portfolio and benchmark portfolio
target - rf = alpha + beta * (benchmark - rf) + error
Parameters
-----------------
target: series, portfolio return
benchmark: series, portfolio return
rf: float/int/series, risk-free rate
Returns
-----------------
float: beta
'''
target_excess = np.subtract(target, rf)
benchmark_excess = np.subtract(benchmark, rf)
return np.cov(target_excess,benchmark_excess,ddof=0)[0,1]/np.var(benchmark_excess,ddof=0)
def calculate_alpha(target,benchmark,rf):
'''
Calculate alpha of excess returns, using OLS method, between target portfolio and benchmark portfolio
target - rf = alpha + beta * (benchmark - rf) + error
Parameters
-----------------
target: series, portfolio return
benchmark: series, portfolio return
rf: float/int/series, risk-free rate
freq: int, frequency of portfolio
Returns
-----------------
float: alpha
'''
target_excess = np.subtract(target,rf)
benchmark_excess = np.subtract(benchmark,rf)
beta = calculate_beta(target,benchmark,rf)
alpha = np.mean(np.subtract(target_excess,beta*benchmark_excess))
return alpha #*freq # annualized alpha by simply multiplying the frequency of the portfolio(this is a estiamted method)
def calculate_treynor_ratio(target,benchmark,rf,freq):
'''
Calculate Treynor Ratio(TR) based on beta of excess returns
TR = (annualized_return(target) - annualized_return(risk free))/beta(target,benchmark)
Parameters
-----------------
target: series, portfolio return
benchmark: series, portfolio return
rf: float/int/series, risk-free rate, if it is a scalar which should be a annualized risk free rate
freq: int,frequency of the portfolio return
Returns
-----------------
float: Treynor Ratio
'''
ann_return_target = calculate_annualized_return(target,freq)
if type(rf) is pd.Series:
ann_return_rf = calculate_annualized_return(rf,freq)
else:
ann_return_rf = rf
return (ann_return_target - ann_return_rf)/calculate_beta(target,benchmark,rf)
def calculate_sortino_ratio(target,benchmark):
'''
Calculate Sortino Ratio(SR), using normal distribution to approximate target portfolio return
***Notice that the SR is not based on annual frequency but the frequency of target portfolio
SR = (R-T)/DR
* R : average realized return of target portfolio
T : required rate of return , defined by average realized return of benchmark portfolio
DR : downside deviation E[(r-T)^2] on interval (-inf,T)
r : random variable representing target portfolio return with normal distribution approximation
Parameters
-----------------
target: series, portfolio return
benchmark: series, portfolio return
Returns
-----------------
float: Sortino Ratio
'''
R = target.mean()
T = benchmark.mean()
mu, sig = st.norm.fit(target[1:]) # first date contains no return
DR = np.sqrt(st.norm.expect(func=lambda x: (x-T)**2, loc=mu,scale=sig,lb=-np.inf,ub=T))
return (R-T)/DR
def calculate_information_ratio(target,benchmark,freq):
'''
Calculate Information Ratio(IR) for annualized excess returns
IR = R/S
* R : annualized return of excess returns
S : annualized standard deviation of excess returns
excess returns: target_portfolio_return(t) - benchmark_portfolio_return(t)
Parameters
-----------------
target: series, portfolio return
benchmark: series, portfolio return
freq: int,frequency of the portfolio return
Returns
-----------------
float: Information Ratio
'''
ex = np.subtract(target , benchmark)
return calculate_annualized_return(ex,freq)/calculate_annualized_stdev(ex,freq)
_portfolio_return_statistics_func_mapper = \
{'Annualized Return':calculate_annualized_return, # scalar
'Latest Annualized Return':calculate_latest_annualized_returns, # pandas series
'Annualized Standard Deviation':calculate_annualized_stdev, # scalar
'Latest Annualized Standard Deviation':calculate_latest_annualized_stdev, # pandas series
'Month Rolling Return':calculate_rolling_returns, # pandas series
'Calendar Year Return':calculate_calendar_year_returns, # pandas series
'Percentile 10': calculate_percentile, # scalar
'Percentile 25': calculate_percentile, # scalar
'Percentile 50': calculate_percentile, # scalar
'Percentile 75': calculate_percentile, # scalar
'Percentile 90': calculate_percentile, # scalar
'Momentum':calculate_momentum, # scalar
'Return Risk Ratio':calculate_return_risk_ratio, # scalar
'Skewness':calculate_skewness, # scalar
'Kurtosis':calculate_kurtosis, # scalar
'CVaR':calculate_VaR_CVaR, # scalar,(with method = 'norm_CVaR')
'Drawdown':calculate_drawdown, # pandas series
'Max Drawdown':calculate_max_drawdown, # scalar
'Batting Average':calculate_batting_avg, # scalar
'Beta':calculate_beta, # scalar
'Alpha':calculate_alpha, # scalar
'Treynor Ratio':calculate_treynor_ratio, # scalar
'Sortino Ratio':calculate_sortino_ratio, # scalar
'Information Ratio':calculate_information_ratio} # scalar
def get_portfolio_return_statistics_func_mapper(func_mapper = _portfolio_return_statistics_func_mapper):
return func_mapper
def get_portfolio_return_statistics_func_list(func_mapper = _portfolio_return_statistics_func_mapper):
return list(func_mapper.keys())
def get_portfolio_return_statistics_param_mapper(portfolio_return=None,freq=None,month_size=None,N=None,benchmark=None,rf=0):
portfolio_return_statistics_param_mapper = \
{'Annualized Return':{'portfolio_return':portfolio_return,'freq':freq},# method = 'direct'\
'Latest Annualized Return':{'portfolio_return':portfolio_return,'freq':freq},\
'Annualized Standard Deviation':{'portfolio_return':portfolio_return,'freq':freq}, # ddof = 1\
'Latest Annualized Standard Deviation':{'portfolio_return':portfolio_return,'freq':freq},\
'Month Rolling Return':{'portfolio_return':portfolio_return,'freq':freq,'month_size':month_size},\
'Calendar Year Return':{'portfolio_return':portfolio_return,'freq':freq},\
'Percentile 10':{'portfolio_return':portfolio_return,'pos':10},\
'Percentile 25':{'portfolio_return':portfolio_return,'pos':25},\
'Percentile 50':{'portfolio_return':portfolio_return,'pos':50},\
'Percentile 75':{'portfolio_return':portfolio_return,'pos':75},\
'Percentile 90':{'portfolio_return':portfolio_return,'pos':90},\
'Momentum':{'portfolio_return':portfolio_return,'N':N},\
'Return Risk Ratio':{'portfolio_return':portfolio_return,'freq':freq},\
'Skewness':{'portfolio_return':portfolio_return},\
'Kurtosis':{'portfolio_return':portfolio_return},\
'CVaR':{'portfolio_return':portfolio_return}, # method = 'norm_CVaR', alpha = 0.05\
'Drawdown':{'portfolio_return':portfolio_return},\
'Max Drawdown':{'portfolio_return':portfolio_return},\
'Batting Average':{'target':portfolio_return,'benchmark':benchmark},\
'Beta':{'target':portfolio_return,'benchmark':benchmark,'rf':rf},\
'Alpha':{'target':portfolio_return,'benchmark':benchmark,'rf':rf},\
'Treynor Ratio':{'target':portfolio_return,'benchmark':benchmark,'rf':rf,'freq':freq},\
'Sortino Ratio':{'target':portfolio_return,'benchmark':benchmark},\
'Information Ratio':{'target':portfolio_return,'benchmark':benchmark,'freq':freq}}
return portfolio_return_statistics_param_mapper
def calculate_statistics_of_interest(func_mapper,param_mapper,func_of_interest):
def param_parse(param_mapper):
old_new_dict = {}
for f in func_of_interest:
params_dict = param_mapper[f]
params_name = params_dict.keys()
params_name_modify = [pn for pn in params_name if pn not in ('portfolio_return','freq','target','rf','pos')]
for pnm in params_name_modify:
if np.isscalar(param_mapper[f][pnm]):
new_info = str(param_mapper[f][pnm])
old_new_dict[f] = '{} {}'.format(new_info,f)
else:
new_info = str(param_mapper[f][pnm].name)
old_new_dict[f] = '{} vs {}'.format(f,new_info)
return old_new_dict
result = dict(zip(func_of_interest,[func_mapper[f](**param_mapper[f]) for f in func_of_interest]))
old_new_dict = param_parse(param_mapper)
for item in old_new_dict.items():
result[item[1]] = result.pop(item[0])
return result
def calculate_common_statistics(portfolio_return,freq,N=None):
'''
Calculate common statistics(only scalar result) that can be computed with a single portfolio return(no benchmark)
Parameters
-----------------
portfolio_return: series, portfolio return
freq: int, frequency of portfolio
N: int, used to calculate momentum from N+1 period before
Returns
-----------------
series, with name of the regarding strategy and
index as the statistics' name
'''
if N is None:
N = portfolio_return.size
common_param_mapper=get_portfolio_return_statistics_param_mapper(portfolio_return=portfolio_return,freq=freq,N=N)
common_func_list = ['Annualized Return','Annualized Standard Deviation','Skewness','Kurtosis','Return Risk Ratio','CVaR','Momentum',\
'Max Drawdown','Percentile 10','Percentile 25','Percentile 50','Percentile 75','Percentile 90']
func_mapper = get_portfolio_return_statistics_func_mapper()
common_stats = calculate_statistics_of_interest(func_mapper,common_param_mapper,common_func_list)
return pd.Series(common_stats,name=portfolio_return.name)
def calculate_scalar_statistics(portfolio_return,freq,N=None,benchmark=None,rf=0,only_benchmark=True):
'''
Calculate common statistics(only scalar result) that can be computed with a single portfolio return(no benchmark)
Parameters
-----------------
portfolio_return: series, portfolio return
freq: int, frequency of portfolio
N: int, used to calculate momentum from N+1 period before
benchmark
Returns
-----------------
series, with name of the regarding strategy and
index as the statistics' name
'''
common_statistics = calculate_common_statistics(portfolio_return,freq,N)
if benchmark is None:
return common_statistics
else:
other_param_mapper=get_portfolio_return_statistics_param_mapper(portfolio_return=portfolio_return,freq=freq,N=N,benchmark=benchmark,rf=rf)
other_func_list = ['Batting Average','Beta','Treynor Ratio','Sortino Ratio','Information Ratio']
func_mapper = get_portfolio_return_statistics_func_mapper()
other_stats = calculate_statistics_of_interest(func_mapper,other_param_mapper,other_func_list)
other_stats = pd.Series(other_stats,name=portfolio_return.name)
if only_benchmark:
return other_stats
else:
return pd.concat([common_statistics,other_stats],axis=0)
def calculate_all(weights,returns,name,freq,month_size,N):
'''
Calculate all information that can be computed with a strategy history and corresponding assets' returns
and a few other necessary inputs
Parameters
-----------------
weights: dataframe, strategy history
returns: dataframe, corresponding assets return history
***: weights and returns have same column names and date index
name: str, name of the strategy
freq: int, frequency of the portfolio
month_size: int, window length to compute rolling returns for portfolio return, in terms of month
N: int, number of periods to compute momentum for portfolio return
Returns
-----------------
output: dict, keys for name and values for regarding information
'''
output = {}
portfolio_return = calculate_portfolio_return(weights,returns,name)
#print(any_portfolio)
output['Return'] = portfolio_return # strategy/portfolio return history
output['{}-Month Rolling Return'.format(month_size)] = calculate_rolling_returns(portfolio_return,month_size,freq)
output['Calendar Year Return'] = calculate_calendar_year_returns(portfolio_return,freq)
output['Drawdown'] = calculate_drawdown(portfolio_return)
output["Statistics"] = calculate_statistics(portfolio_return,freq,N)
output["Annualized Return"] = calculate_latest_annualized_returns(portfolio_return,freq)
output["Annualized Standard Deviation"] = calculate_latest_annualized_stdev(portfolio_return,freq)
return output