|
3 | 3 | import datetime
|
4 | 4 | import datetime as dt
|
5 | 5 | from LiabilityClasses import Liability
|
| 6 | +from Agent import ollama_bigger |
6 | 7 |
|
7 | 8 | def create_cashflow_dataframe(cf_dict:dict, unique_dates:list) -> pd.DataFrame:
|
8 | 9 | """
|
@@ -178,18 +179,25 @@ def trade(current_date: dt.date, bank_account:pd.DataFrame, eq_units:pd.DataFram
|
178 | 179 | List with the Dataframe documenting the number of units after trading and the bank_account DataFrame with the
|
179 | 180 | updated bank account balance for the modelling date.
|
180 | 181 | """
|
| 182 | + |
181 | 183 | total_market_value = sum(eq_units[current_date]*eq_price[current_date])+sum(bd_units[current_date]*bd_price[current_date]) # Total value of portfolio after growth
|
182 | 184 |
|
183 |
| - if total_market_value <= 0: |
| 185 | + response_MV = ollama_bigger(total_market_value) |
| 186 | + response_bank = ollama_bigger(bank_account[current_date][0]) |
| 187 | + |
| 188 | +# if total_market_value <= 0: |
| 189 | + if response_MV["message"]["content"] == "N" or response_MV["message"]["content"] == "N.": |
184 | 190 | pass
|
185 |
| - elif bank_account[current_date][0] < 0: # Sell assets |
| 191 | +# elif bank_account[current_date][0] < 0: # Sell assets |
| 192 | + elif response_bank["message"]["content"] == "N" or response_bank["message"]["content"] == "N.": # Sell assets |
186 | 193 | percent_to_sell = min(1, -bank_account[current_date][0] / total_market_value) # How much of the portfolio needs to be sold
|
187 | 194 | eq_units[current_date] = eq_units[current_date] * (1 - percent_to_sell)
|
188 | 195 | bd_units[current_date] = bd_units[current_date] * (1 - percent_to_sell)
|
189 | 196 |
|
190 | 197 | bank_account[current_date] += total_market_value - sum(eq_units[current_date]*eq_price[current_date])-sum(bd_units[current_date]*bd_price[current_date]) # Add cash to bank account equal to shares sold
|
191 | 198 |
|
192 |
| - elif bank_account[current_date][0] > 0: # Buy assets |
| 199 | +# elif bank_account[current_date][0] > 0: # Buy assets |
| 200 | + elif response_bank["message"]["content"] =="Y" or response_bank["message"]["content"] =="Y.": # Buy assets |
193 | 201 | percent_to_buy = bank_account[current_date][0] / total_market_value # What % of the portfolio is the excess cash
|
194 | 202 | eq_units[current_date] = eq_units[current_date] * (1 + percent_to_buy)
|
195 | 203 | bd_units[current_date] = bd_units[current_date] * (1 + percent_to_buy)
|
|
0 commit comments