last day (14 days later) » 

8:47 AM
0
Q: Calculation not storing in DataFrame but works on print

SpuriousI have the following calculation: np.maximum(0, np.prod([perf_asset, calc_arr['val']]) - amt_payout - np.prod([exposure, calc_arr['delta_1']])) Written out, this would be: MAX(0, 0.8 × 105.015038 - 80 - TRUE × 5.3135) MAX(0, 84.0120307692 - 80 - 5.3135) = 0 If I print this, the output actua...

 
It is interesting. If use a = np.maximum(0, np.prod([perf_asset, calc_arr['val']]) - amt_payout - np.prod([exposure, calc_arr['delta_1']])) and cppi['added_amt'] = a it doestn work too?
Or maybe need cppi.ix[0, 'added_amt'] = a, because cppi['added_amt'] get scalar value to all column.
 
No, returns NaN in the array as well but prints correctly.
 
so value of a is NaN?
 
No, value of a is 0, as it should be.
 
So cppi['added_amt'] = 0 doenst work also?
 
8:47 AM
The funny thing is, the calculations all worked once upon a time. I will try the .ix route.
Storing it as 0 does work
It is actually the second iteration where it stops working. It works fine on the first.
 
So it is weird.
Hmmm, some loop? Can you explain more and add code with loop?
 
Ok, will do.
Added the loop.
 
So loop works?
 
Well everything used to work but now it doesn't. It is weird. The loop goes through, yes. The def works if I manually type in the values but it doesn't if I use previous inputs. Does that make sense to you?
 
Please check my answer. If it doesnt work, what is stock_vals after filling in loop?
 
9:15 AM
Your answer still does not change the outcome of the calculations unfortunately.
 
what is stock_vals after filling in loop?
And what is print (cppi.info()) and print (len(stock_vals))
 
I have now got it to work by using np.sum().
This is cppi.info():
<class 'pandas.core.frame.DataFrame'>
Int64Index: 1 entries, 1 to 1
Data columns (total 14 columns):
date               1 non-null int64
perf_risky         1 non-null float64
perf_risk_free     1 non-null float64
gap_payment        1 non-null int64
delta_1            1 non-null float64
cppi_val           1 non-null float64
lockin_amt         1 non-null float64
protected_amt      0 non-null float64
extra_cushion      1 non-null float64
cushion            0 non-null float64
alloc_risky        0 non-null float64
The values are not corresponding because my calculations are a bit more complex than my question indicated but the gist of it is the same.
 
Super, so your DataFrame has only one row?
 
Yes, it does. It is only used for the def.
Afterwards it is returned in the loop, to be a) stored in the stock_vals DataFrame and b) used as an input provider for the next loop iteration.
 
I am little confused.
My main problem is I cannot test it, because some code is missing and I have no your data. So can you rewrite question some way for working for me?
 
9:25 AM
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import random

#Set initial variables
init_investment = 100
reg_investment = 0
investment_freq = '0'
prot_lvl = 0.8
lockin_pct = 0.8
multiplier = 5
init_delta_1 = 5
exposure_edition = True

#Simulation
exp_return = 0.05
exp_vola = 0.15
trading_days = 260
mu = exp_return / trading_days
sigma = exp_vola * np.sqrt(1 / trading_days)
##print('Enter the number of runs')
##NoOfRuns = input()
##print('Es werden ' + str(NoOfRuns) + ' Simulationen durchgeführt.')
This is the entire code
This might fix the entire thing: protected_amt = np.prod([1, protected_amt])
I got it to work now but it's weird
 

last day (14 days later) »