Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to define two functions run simultaneously within a function?
#1
Dear Python Users,

I have the code below. The problem is that two functions are interdependent and should be run simultaneously (line - 8 and 11). How can I run the re-construct the code? The Final output is the value of "call" the gives the minimum value of "diff"

warrant_price = []
diff = []
def results(S0, K, T, r, sigma, k, N, M, Iteration):
    for i in range(1, Iteration):
        dilution = N/(N +k*M)
        Value_2 = 10000
        Value_1= 10000
        warrant = dilution*bsm_call_value(Value_2/N,100,1,0.1,0.2)
        warrant_price.append(warrant) 
        Value_2 = Value_1 + warrant*M
        diff1 = Value_1 - Value_2
        diff.append(diff1) 
        
print(results(100,100,1,0.1,0.2,1,100,10, 10))
call_df = pd.DataFrame({'warrant_price': warrant_price})
diff_df = pd.DataFrame({'diff': diff})
merged_df = call_df.join(diff_df)
merged_df.loc[merged_df['diff'].idxmin()]

Quote
#2
Hello,

I am unsure what is the objective you are trying to reach, but it looks like you are performing multiple runs of call valuations using the BSM model. Would it make sense in your setup to give a default value to Value_2 before the for loop ? Alternatively, this looks like Value_2 is used in place of St (spot price at time t), maybe you could use this as an additional input to your function instead.

If you give some more details on your objective I might be of help. I am familiar with BSM and derivatives.
Quote
#3
(Feb-06-2018, 06:37 PM)boring_accountant Wrote: Hello, I am unsure what is the objective you are trying to reach, but it looks like you are performing multiple runs of call valuations using the BSM model. Would it make sense in your setup to give a default value to Value_2 before the for loop ? Alternatively, this looks like Value_2 is used in place of St (spot price at time t), maybe you could use this as an additional input to your function instead. If you give some more details on your objective I might be of help. I am familiar with BSM and derivatives.
Thank you for the reply! What I am trying to do is to price a warrant with one unknown (firm value). The idea is that the warrant price is equal to a BSM of european call. Once, a company initiates a warrant its firm value changes (#of Shares * Share_price + warrant). I want to find a warrant value (based on the number of iterations) such that the "initial firm value" - "new firm value"(given the initition of warrant) close to zero.
Quote
#4
Alright, I may not be of help to the general solution, but I can give you some pointers which hopefully will prove useful:
  • Value_2 is not set prior to be used by call1, as indicated in your OP, if that makes sense you can set an initial value prior to the loop being executed for the first time;
  • dilution is set but never used
  • Value_1 is used but never set
  • Value_2 is calculated using Value_1 + call*M where call is list, not a scalar. Did you mean to use call1 ?
  • If Value_1 and Value_2 are floats, it's possible that they may be close enough for your needs but that they will not equal 0. I would suggest storing the result without comparing to 0 so that you can observe yourself if one of the iterations is good enough for your needs.
Quote
#5
(Feb-06-2018, 08:00 PM)boring_accountant Wrote: Alright, I may not be of help to the general solution, but I can give you some pointers which hopefully will prove useful:
  • Value_2 is not set prior to be used by call1, as indicated in your OP, if that makes sense you can set an initial value prior to the loop being executed for the first time;
  • dilution is set but never used
  • Value_1 is used but never set
  • Value_2 is calculated using Value_1 + call*M where call is list, not a scalar. Did you mean to use call1 ?
  • If Value_1 and Value_2 are floats, it's possible that they may be close enough for your needs but that they will not equal 0. I would suggest storing the result without comparing to 0 so that you can observe yourself if one of the iterations is good enough for your needs.
Thank you! I changed the code the way you proposed, but the thing is that call1 and Value_2 are interdependent. So, I do not know how to deal with this. Once I run the code above I got constant diff_df and call_df since Value_2 is not changing. Any suggestions how can I make Value_2 be used for the first interation and all the rest should use new Value_2?
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Need help with a function that calls other functions. skurrtboi 4 182 Sep-30-2019, 09:28 PM
Last Post: stullis
  How to run same process simultaneously exploit123 1 204 Sep-19-2019, 10:08 AM
Last Post: Gribouillis
  How to define a function that calculates the BMI from dataframe DavidGG 2 511 May-30-2019, 03:35 PM
Last Post: volcano63
  Control 2 stepper motor simultaneously jihene 2 513 May-08-2019, 05:27 PM
Last Post: DeaD_EyE
  Moving with objects simultaneously kom2 1 360 Apr-20-2019, 07:12 PM
Last Post: SheeppOSU
  call a function from other functions ... evilcode1 2 658 Sep-05-2018, 09:07 AM
Last Post: evilcode1
  using subpocess for both reading and writing simultaneously dauriac 11 2,779 May-30-2018, 10:09 PM
Last Post: killerrex
  controlling multiple server simultaneously. caligola 3 860 May-11-2018, 05:44 PM
Last Post: wavic
  argument parser: to execute single function, and subsequent functions also raghu 10 1,721 Mar-12-2018, 06:57 AM
Last Post: wavic
  Function to Continuasly monitor serial port and control other functions ricardons 10 2,589 Mar-04-2018, 10:34 PM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)