## Cloud computing with Python and Excel : picloud integration

Further to my previous post about making Python GUI interact with Excel, we thought it would be interesting to test how cloud computing could be easily accessible from Excel using Python and the picloud library.

We have just added interfaced some Python code that do compute the put and call price of a stock based on a Black & Scholes Monte-Carlo simulation. We end up with one function call in Excel :

Implementation details

On the python side, thanks to pyxll, we just need to define a function to interface with Excel using the xl_func decorator :

```from pyxll import xl_func

from picloud_mcarlo import picloud_mcprices
import cloud

cloud.setkey(###, ####)

@xl_func("float S, float K, float T, float r, float sigma, int N, int simulations : float[]", thread_safe=True)
def cloud_mcprices(S0, K, T, r, sigma, N, simulations):
"""
Call the picloud_mcprices with the input coming from Excel and returns an array of put and call prices
"""
return picloud_mcprices(S0, K, T, r, sigma, N, simulations)
```

The cloud call is a simple as :

```def picloud_mcprices(S0, K, T, r, sigma, N, simulations):
"""
Send the simulation on the cloud
FIXME : should manage any problem during computation
"""
jids = [cloud.call(mcprices, S0, K, T, r, sigma, N) for i in range(simulations)]
result = [res for res in cloud.iresult(jids)]
return result

def mcprices(S0, K, T, r, sigma, N=50000):
"""
Call and put option prices using log-normal Monte-Carlo method
"""
scale = S0*numpy.exp((r-sigma**2/2)*T)
[...]
discount = numpy.exp(-r*T)
return [call_pay_off.mean()*discount,
put_pay_off.mean()*discount]
```

Special thanks to Tony Roberts for letting us play with pyxll.