Author Archives: Shawn Zhang
RMBS Prototype Model in Python
Posted by Shawn Zhang
on April 18, 2013
No comments
Parameters
Parameters including : Total balance , Attach point, mortgage rate , Tranche Rate, Payment term and Prepayment CPR .
Cash Flow Chart result:
Full code(2 functions):
def rmbs_show(self):
self.clr_update_frame()
Label( self.update_frame, text="CPR" ).grid( row = 0, column= 0 )
w = Scale( self.update_frame, from_=0.01, to=0.20, resolution = 0.005, orient=HORIZONTAL, variable=self.rmbs_cpr, showvalue = True )
w.grid(row = Read more [...]
A Walk-through on Modeling MBS/Tranche in C#
Posted by Shawn Zhang
on April 12, 2013
No comments
Modeling on MBS/Tranche involves 3 entities . Mortgages , Mortgage Pool and Tranches . Mortgage Pool is key in this relationship . Mortgage Pool collects cash flows from Mortgages and redistribute into different Tranches.
Class MortgagesPool
One Mortgage Pool has many Mortgages and One Mortgage Pool has many Tranches. So , the class of Mortgage Pool may like this :
class MortgagesPool{
public ArrayList tranches = new ArrayList();
public ArrayList mortgages = new ArrayList();
// add a Read more [...]
Bond Calcuation with C#
Posted by Shawn Zhang
on April 11, 2013
No comments
I've been read a tutorial about C# in last 2 days . Before that, I haven't read a single line of C# code in since I started to programming. C# syntax is very similar to C++ and Java . But develop in C# is not easy as its syntax seems. I've wrote some trivial codes about some financial calculation of a bond, it's quite similar to the code I've written before in Python, but this one focus more in a risk neutral perspective.
Basic Bond Class with No Coupon
class ZeroBond{
protected float Read more [...]
Conditional Checking in Python
Posted by Shawn Zhang
on March 22, 2013
No comments
When story begins
In Python , there is a shortcut in conditional checking, I didn't take much care about the difference of below form of conditional syntax :
if var :
stmt;
if var is not None :
stmt;
if var != None:
stmt;
Explanation behind the scene is an analogy to difference of an empty string "" and NULL in a database . "" is an empty string but means something, NULL is nothing means nothing . In Python world , None equals NULL in Database , that's why "" == Read more [...]
Constraints on Arguments in Python
Posted by Shawn Zhang
on March 22, 2013
4 comments
When Dynamic Type comes to Trouble
As a dynamic programming languages , Python don't have a type on variables , as well as a arguments . This feature save us a lot workload and it enable us to focus on logical of program .
def add(x, y):
return x+y
print add(5,6)
>> 11
print add("D","E")
>> "DE"
print add(5.0, 6)
>> 11.0
Above function is straightforward and works fine if x and y are passed with int/ float/ string .
But things may Read more [...]
Download Chinese listed Company's Balance Sheet from Hexun.com
Posted by Shawn Zhang
on January 30, 2013
No comments
I've written a perl script to fetch Balance Sheet data and export them into a Excel spreadsheet .
Pre-preparation:
use LWP::Simple -> this pacake is for scap data from web
use Excel::Writer::XLSX -> for writing excel file
Download
https://github.com/hhh6897/Hexun.Balance.Sheet
Usage :
perl hx.pl [Stock ID sperated by comma] [start year] [end year] [name of output excel spreadsheet]
Result:
Read more [...]
[译文]Decorators and Functional Python[draft]
Posted by Shawn Zhang
on January 16, 2013
No comments
Original blog post wrote by Brian Holdefehr. This is a Chinese version of original post .
本文原文作者 Brian Holdefehr。若有不足,敬请斧正。
装饰器(Decorators) 是Python众多强大特性之一。装饰器除了本身编程语法上的作用之外,另外提供了一种有趣思维方式——"函数化"思维(a functional way)
我会从头开始介绍介绍装饰器的工作原理,接着会介绍几个必须了解的基本概念。之后,我们会详细深入探索一些装饰器实例以及其工作方式。最后我们会讨论一些装饰器的高阶应用,例如参数化装饰器(optional Read more [...]
Get Stock Quote Price API from Yahoo Finance via Python
Posted by Shawn Zhang
on December 28, 2012
No comments
Difference against Google Finance / Sina.com
Yahoo provide more rich function regarding to the Stock API than Google / Sina.com does. particular ,it provide customize return format which customized by supply a parameter in calling URL . Full parameter specification pls refer to this link .(credit to Kelly Elias ) .
200 calls per second , you will be warned if you exceed this limits
csv file returned
No market depth as SIna.com provide
Provide stock indication such as " Earnings Read more [...]
Get Stock Quote from Goolge Web API via Python
Posted by Shawn Zhang
on December 27, 2012
No comments
Background
Google has officially announce that it won't sustain ongoing of Finance API, but there still a available API via URL API . Return data from web server is xml format . We need to parse the return text in Python and extract data .
Get the Stock Data
Google Web API format ( http://www.google.com/ig/api?stock=C ) , this will request market data for security code "C" ( Citigroup :) ) xml return result:
<xml_api_reply version="1">
<finance module_id="0" Read more [...]
Get Security Quote of Chinese Market from Sina.com via Python
Posted by Shawn Zhang
on December 27, 2012
No comments
Intro
Although articles have been written about calling security quote API of Sina.com . I'd like to take a dive into it via Python and try to setup a OO implementation. Sina.com API will offer 5-th market depth prices of Chinese Shanghai / Shenzhen Exchange Stock in real time style .
API structure
calling Sina.com Stock API can be straightforward , just type "http://hq.sinajs.cn/list=sh601012" in browser address . call back will shown as below ( click to enlarge ):
Cracking Read more [...]