返回列表 上一主題 發帖

[發問] ★(發問)一個資料欄位不對稱的資料篩選問題

[發問] ★(發問)一個資料欄位不對稱的資料篩選問題

本帖最後由 yagami12th 於 2012-1-5 12:23 編輯

請教一下大家,昨天晚上在思考一個資料處理的問題,問題如下:

附檔 2010年近月選擇權.rar (249.22 KB)

以下為2010/1月契約資料,以工作表1為例 :                                            (註解:工作表1代表2010/1月,工作表2代表2010/2月,以此類推)

從a2儲存格到a37儲存格為2009/12月17日的"買權"和"賣權"各履約價資料,
從a38儲存格到a73儲存格為2009/12月18日的"買權"和"賣權"各履約價資料,
以此類推 ..
到2010/1/20(註解:未沖銷契約數為未平倉量,買權有買權的未平倉量,賣權有賣權的未平倉量)
(檔案編排一直排不好,sorry,以觀察未沖銷契約數那欄為主)
----------------------------------------------------------------------------------
交易日期             契約        交割月份        履約價        買賣權        開盤價        最高價        最低價        收盤價        成交量        結算價        未沖銷契約數       
2009/12/17        TXO        201001        6900        買權        830        895        805        805        45                 820                                                         176       
2009/12/17        TXO        201001        6900        賣權        16        20        12.5        19.5        7294                 19.5                                                         24820       
2009/12/17        TXO        201001        7000        買權        750        775        720        720        11                 725                                                         85       
2009/12/17        TXO        201001        7000        賣權        20        28        17.5        27        4631                  27                                                         20925       
2009/12/17        TXO        201001        7100        買權        700        700        630        630        2                 630                                                         132       
2009/12/17        TXO        201001        7100        賣權        33        38        23        36.5        5276                  36.5                                                         11340
...
...
2010/1/20
-----------------------------------------------------------------------------------------------------------------------------------------------------
excel相關的涵數有max,min,large,small。找最大用max,找第二或第三大用large


因為 每一天的買權有36檔,賣權也是36檔,
所以先新增一個excel檔案為"2010最大oi",新增12個sheet(因為是12個月),因為有各個不同的履約價,要找出"每一天"的未平倉量最大值是落在哪一個履約價
,以上述的例子為(2010/1月契約)就將找到的資料往2010最大oi.xlsx裡的sheet1貼上(說明:因為在同個excel新增sheet會變的太多,雖然新增sheet比較好寫,)

所以會最後成果會變成:
(在12/17的各檔履約價的買權有36筆)>但對應算出的最大未沖銷契約數], "(註:最大未沖銷契約數又稱最大未平倉量)落在這36筆的哪一檔履約價"如12/17是落在8400的履約價",未平倉量為23299(為最大), 第二大未平倉量的履約價落在 8000的履約價,未平倉量為 21482(第二大)

另外各檔履約價的賣權也有36筆>>也會算出一個最大未沖銷契約數]"是落在哪一檔履約價,與上述的買權說明類似。
---------------------------------------------------
表格格式為:買權為例(以最大值為例)
日期         買權最大未倉量             買權最大未平倉量落在哪個履約價-
12/17       23299                              8400------
12/18       25593                              8400------
12/21      26094                             8400------
..
..
---------------------------------------------------
表格格式為:賣權為例(以最大值為例)
日期         賣權最大未倉量             賣權最大未平倉量落在哪個履約價-
12/17       24820                             6900------
12/18       25593                             6900------
12/21      26450                              6900------
----------------------------------------------------
完成的表格格式為 最後合併:

日期         買權最大未倉量             買權最大未平倉量落在哪個履約價-          賣權最大未倉量             賣權最大未平倉量落在哪個履約價-
12/17       23299                              8400------                                                         24820                             6900------
12/18       25593                              8400------
12/21      26094                             8400------                                                          26450                             6900------

  最後會畫成這樣的圖:http://2330.tw/Option_Master.aspx

上面例子是剛好買權最大未平倉量履約價一直在"8400",常常會有7500跳到7800,又跳到8000的狀況。蠻有趣的一個現象
大概是這樣,不知道我說明的清不清楚..我也還在找處理這個問題的資訊,這個範例能學會應該也能功力大增,謝謝各位。

回復 20# GBKEE

google 一下autofilter 的用法
我好像找到一個解法:
            
       E.Range("A1").AutoFilter 1, Format(i, "yyyy/m/d")
   
改成這樣就可以跑了...
提供給大家參考...

擷取的說明:
http://www.pcreview.co.uk/forums/excel-can-use-variable-autofilter-vba-t3748818.html
======================
This is from "Excel 2002 VBA Programmer's Reference"
Written by John Green, Stephen Bullen, Rob Bovey and Robert Rosenberg

http://www.oaltd.co.uk:80/ExcelProgR...rogRefCh22.htm
Search for "Range.AutoFilter" and you'll see this note:

Range.AutoFilter

The AutoFilter method of a Range object is a very curious beast. We are forced
to pass it strings for its filter criteria and hence must be aware of its string
handling behaviour. The criteria string consists of an operator (=, >, <, >=
etc.) followed by a value.

If no operator is specified, the "=" operator is assumed. The key issue is that
when using the "=" operator, AutoFilter performs a textual match, while using
any other operator results in a match by value. This gives us problems when
trying to locate exact matches for dates and numbers.

If we use "=", Excel matches on the text that is displayed in the cell, i.e. the
formatted number. As the text displayed in a cell will change with different
regional settings and Windows language version, it is impossible for us to
create a criteria string that will locate an exact match in all locales.

There is a workaround for this problem. When using any of the other filter
criteria, Excel plays by the rules and interprets the criteria string according
to US formats. Hence, a search criterion of ">=02/01/2001" will find all dates
on or after 1st Feb, 2001, in all locales.

We can use this to match an exact date by using two AutoFilter criteria. The
following code will give an exact match on 1st Feb, 2001 and will work in any
locale:

Range("A1200").AutoFilter 2, ">=02/01/2001", xlAnd, "<=02/01/2001"

TOP

回復 22# yagami12th


    請教版大...
    無法篩選的問題,是換電腦之後就解決了嗎???
    在 excel2010 執行還是會有問題

    如附圖:

   謝謝!!

TOP

謝謝各位大大的熱心分享
stock

TOP

本帖最後由 GBKEE 於 2012-1-8 13:24 編輯

回復 31# yagami12th
謝謝你

TOP

回復 29# GBKEE

給GBKEE大
經過檢查跟校正之後終於完成
這個是完成的檔案(2007到2011):

2007_2011總合.rar (377.87 KB)

TOP

回復 29# GBKEE

不是,昨天真的怪怪的 夾帶好久,我是中學生等級,所以是1mb,2009年近月的資料八月的資料有點問題,我正在修正中,下午一點左右應該可以做好完整版的圖。

TOP

回復 28# yagami12th
可能是你還不熟悉上傳檔案吧!
文件尺寸: 小於 2MB   
可用擴展名: chm, pdf, zip, rar, tar, gz, bzip2, gif, jpg, jpeg, png

TOP

本帖最後由 yagami12th 於 2012-1-7 20:36 編輯

回復 26# GBKEE

回GBKEE大,我做一個從2007年到現在的的圖做好再讓你看看,之前回覆都不知道要按回覆按紐,抱歉。

論壇的夾帶檔案好像出很大的問題,我下午弄了好久,另外我翻的書裡面都找不到GBKEE大的這幾次分享進階程式碼。

TOP

本帖最後由 yagami12th 於 2012-1-6 19:22 編輯

回復 25# GBKEE大
我才要特別感謝你,不然的話不知要摸多久,今天都在東查名查,簡單程式弄到一半有點失焦了。
因為目前處理的都是期貨跟選擇權的每日資料,所以另外再抓最高最低價貼過來也還OK。

但是之後處理到每分每秒的選擇權資料就需要程式的功力了,台股交易時間五小時,以每分鐘頻率資料為例:就是原本EXCEL檔的資料量乘以300,如果是每秒鐘的委託資料就要將原資料量乘以5000至10000(註:因為一秒鐘內常發生30筆到70筆的交易,開盤附近很常見),另外,選擇權履約價這麼多,資料量會十分驚人,期貨的話就還好,因為期貨只有一個。

關於最高最低價等資料,不知道GBKEE大是否需要,我把他放上來。剛找這個資料找了一下,不然很快就回文了。

附件如下:             期貨與現貨日資料("1990/1/4至今,1998/7/21至今")(註:是最完整的資料)這次我有記得,2003跟2010版皆有。
期現貨數據資料03版跟2010版.rar (520.56 KB)

TOP

        靜思自在 : 不怕事多,只怕多事。
返回列表 上一主題