<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>R on Petri Rautiainen</title>
    <link>https://petrirautiainen.netlify.com/categories/r/</link>
    <description>Recent content in R on Petri Rautiainen</description>
    <generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator>
    <language>en-us</language>
    <lastBuildDate>Fri, 07 Jun 2019 00:00:00 +0000</lastBuildDate>
    
	    <atom:link href="https://petrirautiainen.netlify.com/categories/r/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Python with Reticulate</title>
      <link>https://petrirautiainen.netlify.com/post/python-with-reticulate/</link>
      <pubDate>Fri, 07 Jun 2019 00:00:00 +0000</pubDate>
      
      <guid>https://petrirautiainen.netlify.com/post/python-with-reticulate/</guid>
      <description>


&lt;p&gt;Let’s download some packages.&lt;/p&gt;
&lt;p&gt;And calculate European call.&lt;/p&gt;
&lt;pre class=&#34;python&#34;&gt;&lt;code&gt;import math
import numpy as np
from timeit import default_timer as timer
start = timer()
S = 100
K = 105 
T = 1 
r = 0.05
sigma = 0.2
I = 100000
z = np.random.standard_normal(I)
ST = S * np.exp((r-0.5*sigma**2)*T + sigma * math.sqrt(T)*z)
hT = np.maximum(ST - K, 0)
C0 = math.exp(-r*T)*np.mean(hT)
print(&amp;#39;Value of %5.3f.&amp;#39; % C0)&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Value of 8.008.&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&#34;python&#34;&gt;&lt;code&gt;end = timer()
print(&amp;#39;Elapsed time in seconds %5.3f.&amp;#39; % (end - start))&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## Elapsed time in seconds 0.142.&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And in R.&lt;/p&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;start = Sys.time()
S = 100
K = 105 
T = 1 
r = 0.05
sigma = 0.2
I = 100000
z = rnorm(I)
ST = S * exp((r-0.5*sigma**2)*T + sigma * sqrt(T)*z)
hT = pmax(ST - K, 0)
C0 = exp(-r*T)*mean(hT)
C0&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] 7.995249&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&#34;r&#34;&gt;&lt;code&gt;end = Sys.time() - start
print(paste(&amp;quot;Elapsed time in seconds:&amp;quot;, end))&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;## [1] &amp;quot;Elapsed time in seconds: 0.0197596549987793&amp;quot;&lt;/code&gt;&lt;/pre&gt;
</description>
    </item>
    
  </channel>
</rss>
