@@ -37,7 +37,8 @@ def unary_vectorized_roll(arr, window, out=None, **kwargs):
37
37
window : int
38
38
Size of the rolling window in terms of the periodicity of the data.
39
39
out : array-like, optional
40
- The array to store the store the output.
40
+ Array to use as output buffer.
41
+ If not passed, a new array will be created.
41
42
**kwargs
42
43
Forwarded to :func:`~empyrical.{name}`.
43
44
@@ -58,7 +59,7 @@ def unary_vectorized_roll(arr, window, out=None, **kwargs):
58
59
out = np .empty (0 , dtype = 'float64' )
59
60
60
61
if allocated_output and isinstance (arr , pd .Series ):
61
- out = pd .Series (out )
62
+ out = pd .Series (out , index = arr . index [ - len ( out ):] )
62
63
63
64
return out
64
65
@@ -84,7 +85,8 @@ def binary_vectorized_roll(lhs, rhs, window, out=None, **kwargs):
84
85
window : int
85
86
Size of the rolling window in terms of the periodicity of the data.
86
87
out : array-like, optional
87
- The array to store the store the output.
88
+ Array to use as output buffer.
89
+ If not passed, a new array will be created.
88
90
**kwargs
89
91
Forwarded to :func:`~empyrical.{name}`.
90
92
@@ -109,9 +111,9 @@ def binary_vectorized_roll(lhs, rhs, window, out=None, **kwargs):
109
111
110
112
if allocated_output :
111
113
if out .ndim == 1 and isinstance (lhs , pd .Series ):
112
- out = pd .Series (out )
114
+ out = pd .Series (out , index = lhs . index [ - len ( out ):] )
113
115
elif out .ndim == 2 and isinstance (lhs , pd .Series ):
114
- out = pd .DataFrame (out )
116
+ out = pd .DataFrame (out , index = lhs . index [ - len ( out ):] )
115
117
return out
116
118
117
119
binary_vectorized_roll .__doc__ = binary_vectorized_roll .__doc__ .format (
@@ -203,16 +205,16 @@ def cum_returns(returns, starting_value=0, out=None):
203
205
starting_value : float, optional
204
206
The starting returns.
205
207
out : array-like, optional
206
- The array to store the store the output.
208
+ Array to use as output buffer.
209
+ If not passed, a new array will be created.
207
210
208
211
Returns
209
212
-------
210
213
cumulative_returns : array-like
211
214
Series of cumulative returns.
212
215
"""
213
-
214
216
if len (returns ) < 1 :
215
- return type ( returns )([] )
217
+ return returns . copy ( )
216
218
217
219
nanmask = np .isnan (returns )
218
220
if np .any (nanmask ):
@@ -233,9 +235,9 @@ def cum_returns(returns, starting_value=0, out=None):
233
235
234
236
if allocated_output :
235
237
if returns .ndim == 1 and isinstance (returns , pd .Series ):
236
- out = pd .Series (out )
238
+ out = pd .Series (out , index = returns . index )
237
239
elif isinstance (returns , pd .DataFrame ):
238
- out = pd .DataFrame (out )
240
+ out = pd .DataFrame (out , index = returns . index )
239
241
240
242
return out
241
243
@@ -318,7 +320,8 @@ def max_drawdown(returns, out=None):
318
320
Daily returns of the strategy, noncumulative.
319
321
- See full explanation in :func:`~empyrical.stats.cum_returns`.
320
322
out : array-like, optional
321
- The array to store the store the output.
323
+ Array to use as output buffer.
324
+ If not passed, a new array will be created.
322
325
323
326
Returns
324
327
-------
@@ -471,7 +474,8 @@ def annual_volatility(returns,
471
474
returns into annual returns. Value should be the annual frequency of
472
475
`returns`.
473
476
out : array-like, optional
474
- The array to store the store the output.
477
+ Array to use as output buffer.
478
+ If not passed, a new array will be created.
475
479
476
480
Returns
477
481
-------
@@ -635,7 +639,8 @@ def sharpe_ratio(returns,
635
639
returns into annual returns. Value should be the annual frequency of
636
640
`returns`.
637
641
out : array-like, optional
638
- The array to store the store the output.
642
+ Array to use as output buffer.
643
+ If not passed, a new array will be created.
639
644
640
645
Returns
641
646
-------
@@ -713,7 +718,8 @@ def sortino_ratio(returns,
713
718
The downside risk of the given inputs, if known. Will be calculated if
714
719
not provided.
715
720
out : array-like, optional
716
- The array to store the store the output.
721
+ Array to use as output buffer.
722
+ If not passed, a new array will be created.
717
723
718
724
Returns
719
725
-------
@@ -792,7 +798,8 @@ def downside_risk(returns,
792
798
returns into annual returns. Value should be the annual frequency of
793
799
`returns`.
794
800
out : array-like, optional
795
- The array to store the store the output.
801
+ Array to use as output buffer.
802
+ If not passed, a new array will be created.
796
803
797
804
Returns
798
805
-------
@@ -857,7 +864,8 @@ def excess_sharpe(returns, factor_returns, out=None):
857
864
factor_returns: float / series
858
865
Benchmark return to compare returns against.
859
866
out : array-like, optional
860
- The array to store the store the output.
867
+ Array to use as output buffer.
868
+ If not passed, a new array will be created.
861
869
862
870
Returns
863
871
-------
@@ -962,7 +970,8 @@ def alpha_beta(returns,
962
970
returns into annual returns. Value should be the annual frequency of
963
971
`returns`.
964
972
out : array-like, optional
965
- The array to store the store the output.
973
+ Array to use as output buffer.
974
+ If not passed, a new array will be created.
966
975
967
976
Returns
968
977
-------
@@ -994,7 +1003,8 @@ def roll_alpha_beta(returns, factor_returns, window=10, **kwargs):
994
1003
window : int
995
1004
Size of the rolling window in terms of the periodicity of the data.
996
1005
out : array-like, optional
997
- The array to store the store the output.
1006
+ Array to use as output buffer.
1007
+ If not passed, a new array will be created.
998
1008
**kwargs
999
1009
Forwarded to :func:`~empyrical.alpha_beta`.
1000
1010
"""
@@ -1046,7 +1056,8 @@ def alpha_beta_aligned(returns,
1046
1056
returns into annual returns. Value should be the annual frequency of
1047
1057
`returns`.
1048
1058
out : array-like, optional
1049
- The array to store the store the output.
1059
+ Array to use as output buffer.
1060
+ If not passed, a new array will be created.
1050
1061
1051
1062
Returns
1052
1063
-------
@@ -1114,7 +1125,8 @@ def alpha(returns,
1114
1125
The beta for the given inputs, if already known. Will be calculated
1115
1126
internally if not provided.
1116
1127
out : array-like, optional
1117
- The array to store the store the output.
1128
+ Array to use as output buffer.
1129
+ If not passed, a new array will be created.
1118
1130
1119
1131
Returns
1120
1132
-------
@@ -1182,7 +1194,8 @@ def alpha_aligned(returns,
1182
1194
The beta for the given inputs, if already known. Will be calculated
1183
1195
internally if not provided.
1184
1196
out : array-like, optional
1185
- The array to store the store the output.
1197
+ Array to use as output buffer.
1198
+ If not passed, a new array will be created.
1186
1199
1187
1200
Returns
1188
1201
-------
@@ -1241,7 +1254,8 @@ def beta(returns, factor_returns, risk_free=0.0, out=None):
1241
1254
Constant risk-free return throughout the period. For example, the
1242
1255
interest rate on a three month us treasury bill.
1243
1256
out : array-like, optional
1244
- The array to store the store the output.
1257
+ Array to use as output buffer.
1258
+ If not passed, a new array will be created.
1245
1259
1246
1260
Returns
1247
1261
-------
@@ -1282,7 +1296,8 @@ def beta_aligned(returns, factor_returns, risk_free=0.0, out=None):
1282
1296
Constant risk-free return throughout the period. For example, the
1283
1297
interest rate on a three month us treasury bill.
1284
1298
out : array-like, optional
1285
- The array to store the store the output.
1299
+ Array to use as output buffer.
1300
+ If not passed, a new array will be created.
1286
1301
1287
1302
Returns
1288
1303
-------
0 commit comments