从有Samsung Galaxy Note 的消息开始,就很期待这款 5.3 寸屏的手机(5.3 寸啊!5.3 寸啊!5.3 寸啊!),但是不出所料,这款手机要很迟才能在北美上市(甚至连会不会上市都还是一个未知数),所以当 Galaxy Note 在欧洲和亚洲发布之后,就只能关注 eBay,等待它从亚欧流入北美。
当欧洲刚刚发布这款手机的时候,eBay 也同步有人开始售卖,一开始的价格大约在 $1000 左右,并且数量很少。等了一段时间,香港的发布会过后,随着大量香港卖家的加入,价钱开始迅速下跌,很快跌倒了$800左右。作为以数字为生的人,当然会“萌”任何时间序列的漂移、扩散和跳跃(不负责的翻译 drift, diffusion, & jump),但是不断的刷新去查看eBay页面是在令人厌恶,于是就写了一个简单的 C# 程序,定时去“挖掘”eBay 页面上的价格。
开始测试时是每两个小时 quote 一次,后来改成一个小时 quote 一次。屏幕上跳出的数字,很像交易所的证券,所以就干脆把它用 chartSeries (R 的 quantmod package)画出来,然后就从数据里发现了很有趣的规律:
当然数据有限,很多只是我的猜测,不过数据本身挺有趣的,不仅本身是一个很 behavior economics的测试,如果数据点足够的多,还能 fit 出一个 term structure 模型来。。。
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
/// <summary>
/// Fetch eBay Price
/// </summary>
class WebFetch
{
static void Main(string[] args)
{
while (true)
{
// used to build entire input
StringBuilder sb = new StringBuilder();
// used on each read operation
byte[] buf = new byte[8192];
// prepare the web page we will be asking for
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create("http://www.ebay.com/ctg/Samsung-Galaxy-Note-32GB-Black-Unlocked-Smartphone-/110509414");
// execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// we will read data via the response stream
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
// fill the buffer with data
count = resStream.Read(buf, 0, buf.Length);
// make sure we read some data
if (count != 0)
{
// translate from bytes to ASCII text
tempString = Encoding.ASCII.GetString(buf, 0, count);
// continue building the string
sb.Append(tempString);
}
}
while (count > 0);
string page = sb.ToString();
//page = Regex.Replace(page, @"<(.|\n)*?>", "");
// print out page source
string targetString = "bbx2-pv";
int first = page.IndexOf(targetString);
string price = page.Substring(first + targetString.Length + 2, 7);
targetString = "ship tfsp bbx2-s";
first = page.IndexOf(targetString);
string temp = page.Substring(first + targetString.Length + 2, 20);
targetString = "</s";
first = temp.IndexOf(targetString);
string shipping = temp.Substring(0, first);
if (shipping == "Free shipping") shipping = "$0";
DateTime time = DateTime.Now;
string path = @"C:\Users\Kai\Dropbox\Mis\Android App\GalaxyNote.txt";
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine("{0}\t{1}\t{2}", time.ToString(), price, shipping);
}
Console.WriteLine("{0}\t{1}\t{2}", time.ToString(), price, shipping);
Thread.Sleep(1000 * 60 * 60);
}
}
}