Python Unit Tests
This article covers briefly how you can run Python Unit Tests against a suite of analytics in Visual Studio 2010 with Python Tools for Visual Studio (PTVS). Visual Studio 2013 Express edition is much more adapted to Python unit testing. Here we explain how you can circumvent this limitation using a main() method to launch this series of tests.
– Install Visual Studio 2010 (full version), or VS Pro (Community Edition, which is free) . You can also install PTVS 2.1 into VS 2013 Express for Web and VS 2013 Express for Desktop editions.
– Install PTVS adpated to your VS version (2013,2013).
– Once you have installed a Python distribution like Anaconda, configure PTVS options as following in VS Tools, Options, Python Tools:
– Create a a new VS solution with a Python application project (i called it “OptionGreeks”)
– Add your Python environment by right-clicking on your Python project ‘Python Environments’, in the Solution explorer:
Analytics library to be tested
The class that we are going to test here is already published in a previous article dedicated to options greeks computation.
Add this .py (OptionsAnalytics.py) to your project.
Depending on your python distribution, you may have to download the package unittest: right-click on your Python environment and select “Install Python Package”.
Now, add to your solution a .py file (i called it “OptionsAnalyticsTestSuite.py”) containing the following code:
from OptionsAnalytics import BSMerton
prem = BSMerton([1,100,100,0.01,0.01,360,0.2]).Premium
prem = BSMerton([-1,100,98,0.01,0.02,180,0.15]).Premium
charm = BSMerton([1,100,102,0.05,0.02,120,0.30]).Charm
charm = BSMerton([-1,100,98,0.01,0.03,15,0.45]).Charm
vanna = BSMerton([-1,100,98,0.01,0.03,15,0.45]).Vanna
theta = BSMerton([1,100,98,0.01,0.03,15,0.45]).Theta
theta = BSMerton([-1,100,98,0.01,0.03,15,0.10]).Theta
vega = BSMerton([1,100,98,0.01,0.03,15,0.45]).Vega
gamma = BSMerton([1,100,98,0.01,0.03,15,0.45]).Gamma
rho = BSMerton([1,100,105,0.05,0.03,60,0.45]).Rho
rho = BSMerton([-1,100,105,0.05,0.03,60,0.45]).Rho
phi = BSMerton([1,100,105,0.05,0.03,60,0.45]).Phi
phi = BSMerton([-1,100,105,0.05,0.03,60,0.45]).Phi
if __name__ == '__main__':
The Python project should look like:
If you set OptionsAnalyticsTestSuite.py to be the startup project, just run it (F5) and you should see in the console window that all tests passed:
Leave a Reply