COCO研究院

 找回密碼
 註冊
搜索
樓主: sjgau

[其他程式語言] 我想要寫 C語言程式設計 分析十年一分鐘K線資料

[複製鏈接]
 樓主| 發表於 12-4-10 09:09 | 顯示全部樓層
cococharles 發表於 12-4-10 08:57
long 是 4 bytes, range 也是到 2,147,483,647
int 是 system dependent, 隨著系統是 16bit, 32bit,64bit ...

樓上的 答案

完全正確

值得嘉獎


發表於 12-4-10 09:15 | 顯示全部樓層
本帖最後由 wtkao 於 12-4-10 09:19 編輯
sjgau 發表於 12-4-10 08:33
(a + 1) < a

我把printf這行用 cout << "b = " << b << " a = " << a << endl; 代替
以Dev-C++執行,跑不出結果(DOS視窗沒出現任何文字訊息)

我印象中群益MultiCharts有送10年份的台股交易資料,應該不需要重新製造車輪吧? @@
 樓主| 發表於 12-4-10 09:32 | 顯示全部樓層
wtkao 發表於 12-4-10 09:15
我把printf這行用 cout

我的 Dev-C++ 可以

不是 重複 製造 車輪的問題,

是 ,。。。
說來話長,慢慢 說,。。。



   printf("b= a + 1= %.3lf, \na=        %.3lf \n", b, a);  
   cout << "b = " << b << " a = " << a << endl;

   /*

b= a + 1= 9008425760425376.000,
a=        9008425760425376.000
b = 9.00843e+015 a = 9.00843e+015
請按任意鍵繼續 . . .

   */


   system("PAUSE");


發表於 12-4-10 09:43 | 顯示全部樓層
b= a + 1= 9008425760425376.000,
a=        9008425760425376.000


b 與 a 的值都相同?
考慮將 b、a 設成 double 型態,會不會好一些? @@
 樓主| 發表於 12-4-10 09:52 | 顯示全部樓層
已經是 double 了

我會慢慢的 詳細的解釋

why?

發表於 12-4-10 11:27 | 顯示全部樓層
sjgau 發表於 12-4-10 08:33
(a + 1) < a

a無上限累加
b永遠為a+1, 說明b會比a提前溢位, 便造成a>b

評分

參與人數 1金錢 +1 收起 理由
sjgau + 1 按一個讚!

查看全部評分

發表於 12-4-10 11:55 | 顯示全部樓層
原來已經從分析一分鐘K,變成C語言教學,會不會跳太遠啦?哈哈!但既然要用C來寫交易策略,當然是要搞清楚語言特性。不過以效率而言,使用Python等Script語言會不會更快更早面對策略上的問題。小弟小小建議啦~
 樓主| 發表於 12-4-10 12:20 | 顯示全部樓層
philipz 發表於 12-4-10 11:55
原來已經從分析一分鐘K,變成C語言教學,會不會跳太遠啦?哈哈!但既然要用C來寫交易策略,當然是要搞清楚 ...

沒有學過 Python

我想,還是從自己熟悉的工具開始


 樓主| 發表於 12-4-10 12:56 | 顯示全部樓層
很簡單的一個副程式,就把一個學生保送進入
期交所工作。

這個問題,大概就是

系統所提供的亂數的範圍很窄。
大概只有 x 到 y,
x= ?
y= ?

如何改進?
必須考慮速度的因素,
產生十億個亂數,你需要多久?

這一題,答對的朋友,送 30元 coco
發表於 12-4-10 13:01 | 顯示全部樓層
philipz 發表於 12-4-10 11:55
原來已經從分析一分鐘K,變成C語言教學,會不會跳太遠啦?哈哈!但既然要用C來寫交易策略,當然是要搞清楚 ...

是阿!完全變成程式設計教室了...
發表於 12-4-10 13:19 | 顯示全部樓層
C or C++ 具有執行效能上的優勢

Facebook 也透過自家開發的HipHop,將PHP code 轉換為 C++ code @@
 樓主| 發表於 12-4-10 13:21 | 顯示全部樓層
jinace 發表於 12-4-10 13:01
是阿!完全變成程式設計教室了...

不想看的,可以忽略。

現在是 剛剛開始,
以後,保證會很精采。

到時候,程度跟不上,
不要怪我

發表於 12-4-10 13:39 | 顯示全部樓層
wtkao 發表於 12-4-10 13:19
C or C++ 具有執行效能上的優勢

Facebook 也透過自家開發的HipHop,將PHP code 轉換為 C++ code @@ ...

是沒錯啦~但是FB一秒的query量這麼大,才有必要針對PHP作優化。
[backcolor=transparent !important]
[color=#fafafa !important][backcolor=#363636 !important]



那...,各位還是加油吧~
 樓主| 發表於 12-4-10 14:36 | 顯示全部樓層
兩個 副程式提供分享

skip()
為了 輸出的段落分明,
用來提供 跳行


pause()
程式暫停的功能





#include <cstdlib>
#include <iostream>

using namespace std;
// ----------------------------------------------

#include <math.h>
#include <conio.h>
// ----------------------------------------------

//   skip(-3);
void skip(int no)
{
   int i;
        
   // 限制 no 在 1 到 20 中間
   if ((no >= 1) && (no <= 20)) {// OK
      for (i=1;i<=no;i++) {
         printf("\n");
      }
   }
   else {// no 不在 1 到 20 中間
      printf("\n");
   }// end if
}// end of skip()
// ----------------------------------------------

//   pause();
void pause(void)
{
   int ch1;
   
   // remove type ahead
   while (kbhit()) {
      ch1= getch();
   }// end while
   
   printf("\n Press [Esc] for program stop! other key for continue ...");
   do {
      // wait for keyPressed
   } while(!kbhit());
   printf("\n");
   ch1= getch();
   
   if (ch1 == 0x1b) {// [Esc] key be pressed
      exit(1);// exit the program
   }
   
   // remove extra key
   while (kbhit()) {
      ch1= getch();
   }
}// end of pause()
// ----------------------------------------------

int main(int argc, char *argv[])
{
   int i;
   
   for (i=1;i<=20;i++) {
      skip(i);
      printf("i= %5d, i*i= %5d, sqrt(i)= %10.6lf \n", i, i*i, sqrt(i));
      pause();
   }// end for
   system("pause");
   return EXIT_SUCCESS;
}// end of main()
 樓主| 發表於 12-4-11 08:27 | 顯示全部樓層
// 這個 計算時間的副程式,可以精確到 (1/64)秒

#include <cstdlib>
#include <iostream>

using namespace std;
// ----------------------------------------------

#include <math.h>
#include <conio.h>
#include <sys/timeb.h>
#include <time.h>
// ----------------------------------------------

#include "sj-01.h"
// ----------------------------------------------

//   time1(    &t1);
void time1(int *t1)
{
   struct _timeb timebuffer;
   _ftime( &timebuffer );
   
   int sec, ms;
   sec= timebuffer.time % (24L*24*60*60);// 對 24天的秒數取餘數
   // max.= 24.855 天
   
   ms= timebuffer.millitm;
   *t1= (sec*1000) + ms;
}// end of time1()
// ----------------------------------------------

//   time2(    t1,        &dt);
void time2(int t1, double *dt)
{
   // get time now
   int t2;
   time1(&t2);  
   
   (*dt)= (t2 - t1)/1000.0;   
   
   // (*dt) must >= 0
   if ((*dt) < 0) {
      // (24L*24*60*60);// 對 24天的秒數取餘數
      (*dt)+= (24L*24*60*60);
   }
}// end of time2()
// ----------------------------------------------

int main(int argc, char *argv[])
{
   // for time1(), time2()
   
   int no, i, sum, t1, t2;
   double dt;
   
   no= 10;
   while (no > 0) {
      time1(&t1);
      sum= 0;
      for (i=1;i<=no;i++) {
         sum+= i;
      }// end for
      time2(t1, &dt);
      
      printf("no= %12ld, sum= %12ld, dt= %10.3lf  \n", no, sum, dt);
      no= (int) (no*1.125);
   }// end while
   pause();
   
   return EXIT_SUCCESS;
}// end of main()
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-6-18 20:02

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 |